﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using VitCode.ObjectResolutionHelper;

namespace VitCode.Castle.Entities
{
    [OrMemo("资源配置")]
    public class Permission : BaseEntity
    {
        protected Guid m_ObjId;
        [OrMemo("受控对象Id")]
        public virtual Guid ObjId
        {
            get { return m_ObjId; }
            set { m_ObjId = value; }
        }

        protected string m_ObjClassName;
        /// <summary>
        /// 受控制对象的类名
        /// </summary>
        [OrMemo("受控对象类名")]
        public virtual string ObjClassName
        {
            get { return m_ObjClassName; }
            set { m_ObjClassName = value; }
        }

        protected Guid m_ResourceId;
        /// <summary>
        /// 控制资源的ID
        /// </summary>
        [OrMemo("资源对象Id")]
        public virtual Guid ResourceId
        {
            get { return m_ResourceId; }
            set { m_ResourceId = value; }
        }

        protected string m_ResourceClassName;
        /// <summary>
        /// 控制资源的类名
        /// </summary>
        [OrMemo("资源对象类名")]
        public virtual string ResourceClassName
        {
            get { return m_ResourceClassName; }
            set { m_ResourceClassName = value; }
        }

        protected string m_OperateNum;
        /// <summary>
        /// 控制标识,表明它是否有特定的限制
        /// </summary>
        [OrMemo("控制描述")]
        public virtual string OperateNum
        {
            get { return m_OperateNum; }
            set { m_OperateNum = value; }
        }

        /// <summary>
        /// 重写Equals方法
        /// </summary>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, this))
                return true;
            if (obj == null)
                return false;
            var sObj = obj as Permission;
            return sObj != null && (sObj.Id == Id || (sObj.ObjId == m_ObjId && sObj.ResourceId==m_ResourceId));
        }

        /// <summary>
        /// 重写GetHashCode方法
        /// </summary>
        public override int GetHashCode()
        {
            int hash = 11;
            hash = 27 * hash * Id.GetHashCode();
            return hash;
        }
    }
}
